home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4983 < prev    next >
Encoding:
Text File  |  1996-08-05  |  958 b   |  42 lines

  1. Path: dfw.dfw.net!not-for-mail
  2. From: jtmcap@dfw.dfw.net (Jerry Jackson)
  3. Newsgroups: comp.lang.c
  4. Subject: sscanf bug??????
  5. Date: 10 Feb 1996 18:08:56 GMT
  6. Organization: DFW Internet Services - DFWNet: 800-2-DFWNet
  7. Message-ID: <4fimvo$82s@fnord.dfw.net>
  8. NNTP-Posting-Host: dfw.dfw.net
  9. X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
  10.  
  11. the following is a program compiled using microway ndp c/c++ compiler.
  12.  
  13. #include <stdio.h>
  14. #include <string.h>
  15.  
  16. main()
  17. {
  18.     char str_1[] = "013196";
  19.     char str_2[] = "13196";
  20.     long res_1, res_2;
  21.  
  22.     sscanf(str_1,"%d",&res_1);
  23.     sscanf(str_2,"%d",&res_2);
  24.  
  25.     printf("\nres_1 = %d",res_1);
  26.     printf("\nres_2 = %d",res_2);
  27. }
  28.  
  29. the output looks like this:
  30.  
  31. res_1 = 89
  32. res_2 = 13196
  33.  
  34.  
  35. microway says that the leading zero causes sscanf to do an octal 
  36. conversion on the integer.  i have not found any documentation to verify 
  37. this.  also other compilers that i use return the value 13196 for both 
  38. calls to sscanf.
  39.  
  40. bug or undocumented feature?
  41.  
  42.